package org.dromara.nursing.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
// import cn.dev33.satoken.annotation.SaCheckPermission; // Already commented out or will be
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.nursing.domain.vo.AdmissionContractVo;
import org.dromara.nursing.domain.bo.AdmissionContractBo;
import org.dromara.nursing.service.IAdmissionContractService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 入住流程
 *
 * @author Xue
 * @date 2025-04-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/nursing/admissionContract")
public class AdmissionContractController extends BaseController {

    private final IAdmissionContractService admissionContractService;

    /**
     * 查询入住流程列表
     */
    // @SaCheckPermission("nursing:admissionContract:list") // 已移除权限验证
    @GetMapping("/list")
    public TableDataInfo<AdmissionContractVo> list(AdmissionContractBo bo, PageQuery pageQuery) {
        return admissionContractService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出入住流程列表
     */
    // @SaCheckPermission("nursing:admissionContract:export") // 已移除权限验证
    @Log(title = "入住流程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(AdmissionContractBo bo, HttpServletResponse response) {
        List<AdmissionContractVo> list = admissionContractService.queryList(bo);
        ExcelUtil.exportExcel(list, "入住流程", AdmissionContractVo.class, response);
    }

    /**
     * 获取入住流程详细信息
     *
     * @param contractId 主键
     */
    // @SaCheckPermission("nursing:admissionContract:query") // 已移除权限验证
    @GetMapping("/{contractId}")
    public R<AdmissionContractVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long contractId) {
        return R.ok(admissionContractService.queryById(contractId));
    }

    /**
     * 新增入住流程
     */
    // @SaCheckPermission("nursing:admissionContract:add") // 已移除权限验证
    @Log(title = "入住流程", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody AdmissionContractBo bo) {
        return toAjax(admissionContractService.insertByBo(bo));
    }

    /**
     * 修改入住流程
     */
    // @SaCheckPermission("nursing:admissionContract:edit") // 已移除权限验证
    @Log(title = "入住流程", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody AdmissionContractBo bo) {
        return toAjax(admissionContractService.updateByBo(bo));
    }

    /**
     * 删除入住流程
     *
     * @param contractIds 主键串
     */
    // @SaCheckPermission("nursing:admissionContract:remove") // 已移除权限验证
    @Log(title = "入住流程", businessType = BusinessType.DELETE)
    @DeleteMapping("/{contractIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] contractIds) {
        return toAjax(admissionContractService.deleteWithValidByIds(List.of(contractIds), true));
    }

    /**
     * 审核入住合同
     * 
     * @param contractId 合同ID
     * @param reviewStatus 审核状态(1:通过 2:退回)
     */
    @Log(title = "入住合同审核", businessType = BusinessType.UPDATE)
    @PutMapping("/review/{contractId}/{reviewStatus}")
    public R<Void> reviewContract(@NotNull(message = "合同ID不能为空") @PathVariable Long contractId,
                         @NotBlank(message = "审核状态不能为空") @PathVariable String reviewStatus) {
        return toAjax(admissionContractService.reviewContract(contractId, reviewStatus));
    }
}
